package com.scst.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.scst.dto.PageQueryDTO;
import com.scst.dto.WrongAddDTO;
import com.scst.dto.WrongTopicDTO;
import com.scst.entity.WrongTopic;
import com.scst.mapper.WrongTopicMapper;
import com.scst.result.PageResult;
import com.scst.service.WrongService;
import com.scst.vo.WrongAddVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class WrongServiceImpl implements WrongService {
    @Autowired
    WrongTopicMapper wrongTopicMapper;
    @Override
    public WrongAddVO generatetopic(WrongAddDTO wrongAddDTO) {
        WrongTopic wrongTopic=new WrongTopic();
        BeanUtils.copyProperties(wrongAddDTO, wrongTopic);
        wrongTopic.setLeadTime(LocalDateTime.now());
        wrongTopic.setWrongID(Long.parseLong(String.valueOf(System.currentTimeMillis())));
        wrongTopic.setNoting(String.valueOf(System.currentTimeMillis()));
        wrongTopic.setSource(WrongTopic.IN_CLASS_TEST);
        wrongTopic.setSubjects(WrongTopic.CHEMISTRY);
        wrongTopic.setMastery(WrongTopic.NO_UNDERSTAND);
        wrongTopicMapper.insert(wrongTopic);
        return null;
    }

    @Override
    public void updateWrong(WrongTopicDTO wrongTopicDTO) {
        WrongTopic wrongTopic =new WrongTopic();
        BeanUtils .copyProperties(wrongTopicDTO ,wrongTopic );
        wrongTopic.setLeadTime(LocalDateTime.now());
        wrongTopicMapper.update(wrongTopic);
    }

    @Override
    public PageResult pageQuery(PageQueryDTO pageQueryDTO) {
        PageHelper.startPage(pageQueryDTO.getPage(),pageQueryDTO.getPageSize());
        Page<WrongTopic> page=wrongTopicMapper.pageQuery(pageQueryDTO);
        long total=page.getTotal();
        List<WrongTopic> records=page.getResult();
        return new PageResult(total,records);
    }
}
